﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace wd_11_timer_v1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        DispatcherTimer timer1 = new DispatcherTimer();
        public MainWindow()
        {
            InitializeComponent();
            btn_timer.Content = "开启定时";

/////启动定时器/////////////////////////////////////////////////////////////////////
            
            timer1.Interval = new TimeSpan(0, 0, 1);
            timer1.Tick += Timer1_Tick;
            timer1.IsEnabled = true;
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            string info = string.Format("{0}", DateTime.Now.ToLocalTime().ToString());
            Trace.WriteLine(info);
            return;
        }

        static bool bChange = true;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (bChange)
            {
                btn_timer.Content = "关闭定时";
                timer1.Start();
            }
            else
            {
                btn_timer.Content = "开启定时";
                timer1.Stop();
            }
            bChange = !bChange; //切换
        }
    }
}
